package com.fs.sys.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
import com.fs.sys.bean.dto.UserDTO;
import com.fs.sys.bean.query.NoRoleUserQuery;
import com.fs.sys.domain.entity.UserEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {
    /**
     * 查询无角色的用户信息
     */
    List<UserDTO> queryUserNoRole(NoRoleUserQuery query);

    @Select("select distinct u.* from sys_user u left join (select user_id, tenant_id from sys_tenant_user) t on t.user_id = u.id ${ew.customSqlSegment}")
    @Results(@Result(column="metadata", property = "metadata", typeHandler = Fastjson2TypeHandler.class))
    List<UserEntity> customSelectList(@Param("ew") Wrapper<UserEntity> queryWrapper);

    @Select("select distinct u.* from sys_user u left join (select user_id, tenant_id from sys_tenant_user) t on t.user_id = u.id ${ew.customSqlSegment}")
    @Results(@Result(column="metadata", property = "metadata", typeHandler = Fastjson2TypeHandler.class))
    <E extends IPage<UserEntity>> E customSelectPage(E page, @Param("ew") Wrapper<UserEntity> queryWrapper);
}
